
clear
do "...\First.do"
********************************************************************************
use "$work\analysis_sample.dta"
keep if inrange(age,40,70)

g help=1 if inrange(timing,-4,0)
bys pnr: egen N_pre_2=total(help)
tab N_pre_2
keep if N_pre_2==5

drop if timing>3
drop if timing<-3

********************************************************************************
*** Table D9
********************************************************************************

* Merge with information about parental illness 
merge m:1 ydernr year using "$work\ydernr_parent_illness.dta"
keep if _merge==3
drop _merge

** PCP parents' - any condition
cap drop yder_any
egen yder_any=rowmax(yder_PCP_cancer yder_PCP_CVC_deaths yder_PCP_diabets yder_PCP_COPD)
replace yder_any=. if yder_PCP_cancer==. &  yder_PCP_CVC_deaths==. & yder_PCP_diabets==. & yder_PCP_COPD==.


cap drop help
cap drop interaction
cap drop interaction2
cap drop help_any

g help=(yder_any==1) if timing==1
replace help=. if yder_any==. & timing==1
bys pnr min_year: egen help_any=max(help)

g interaction2=low_ses*help_any

*****************

sum death if post==1, d
local mean=round(`r(mean)'*1000/1000, 0.00001)
local sd=round(`r(sd)'*1000/1000, 0.00001)

sum death if post==1 & low_ses==1
local mean_low=round(`r(mean)'*1000/1000, 0.00001) 

ttest death if post==1 & help3==0 , by(low_ses)
local mean0= round((`r(mu_2)'-`r(mu_1)')*1000/1000, 0.00001)

reghdfe death help_any low_ses interaction2 $patient_X $gp_X if post==1, a(gp_fe year) cluster(newgpyr)

outreg2 using "$table\TableD9.doc", replace tex label keep(interaction2 help_any low_ses) nocons bdec(5) sdec(5) rdec(5)  addtext(Outcome mean,`mean', Outcome mean low-SES, `mean_low', Gradient  for high SES physicians, `mean0') ctitle(PCP All conditions)

* PCP parents' any CVC

cap drop help
cap drop interaction
cap drop interaction2
cap drop help_cvc
g help=(yder_PCP_CVC_deaths==1) if timing==1
replace help=. if yder_PCP_CVC_deaths==.  & timing==1
bys pnr min_year: egen help_cvc=max(help)

g interaction2=low_ses*help_cvc

sum death if post==1, d
local mean=round(`r(mean)'*1000/1000, 0.00001)
local sd=round(`r(sd)'*1000/1000, 0.00001)

sum death if post==1 & low_ses==1
local mean_low=round(`r(mean)'*1000/1000, 0.00001) 

ttest death if post==1 & help3==0 , by(low_ses)
local mean0= round((`r(mu_2)'-`r(mu_1)')*1000/1000, 0.00001)

reghdfe death help_cvc low_ses interaction2 $patient_X $gp_X if post==1, a(gp_fe year) cluster(newgpyr)

outreg2 using "$table\TableD9.doc", append tex label keep(interaction2 help3 low_ses help_cvc) nocons bdec(5) sdec(5) rdec(5)  addtext(Outcome mean,`mean', Outcome mean low-SES, `mean_low', Gradient  for high SES physicians, `mean0') ctitle(PCP CVC)



* PCP parents' any cancer

cap drop help
cap drop interaction
cap drop interaction2
cap drop help_cancer

g help=(yder_PCP_cancer==1) if timing==1
replace help=. if yder_PCP_cancer==.  & timing==1
bys pnr min_year: egen help_cancer=max(help)

g interaction2=low_ses*help_cancer

sum death if post==1, d
local mean=round(`r(mean)'*1000/1000, 0.00001)
local sd=round(`r(sd)'*1000/1000, 0.00001)

sum death if post==1 & low_ses==1
local mean_low=round(`r(mean)'*1000/1000, 0.00001) 

ttest death if post==1 & help3==0 , by(low_ses)
local mean0= round((`r(mu_2)'-`r(mu_1)')*1000/1000, 0.00001)

reghdfe death help_cancer low_ses interaction2 $patient_X $gp_X if post==1, a(gp_fe year) cluster(newgpyr)

outreg2 using "$table\TableD9.doc", append tex label keep(interaction2 help_cancer low_ses) nocons bdec(5) sdec(5) rdec(5)  addtext(Outcome mean,`mean', Outcome mean low-SES, `mean_low', Gradient  for high SES physicians, `mean0') ctitle(PCP Cancer)



** SPECIFIC CASES

replace death_CVC=. if male==0

* PCP parents CVC on patients' CVC mortality
cap drop interaction2 
g interaction2=low_ses*help_cvc

sum death_CVC if post==1, d
local mean=round(`r(mean)'*1000/1000, 0.00001)
local sd=round(`r(sd)'*1000/1000, 0.00001)

sum death_CVC if post==1 & low_ses==1
local mean_low=round(`r(mean)'*1000/1000, 0.00001) 

ttest death_CVC if post==1 & help3==0 , by(low_ses)
local mean0= round((`r(mu_2)'-`r(mu_1)')*1000/1000, 0.00001)

reghdfe death_CVC help_cvc  low_ses interaction2 $patient_X $gp_X if post==1, a(gp_fe year) cluster(newgpyr)

outreg2 using "$table\TableD9.doc", append tex label keep(interaction2 help_cvc low_ses) nocons bdec(5) sdec(5) rdec(5)  addtext(Outcome mean,`mean', Outcome mean low-SES, `mean_low', Gradient  for high SES physicians, `mean0') ctitle(CVC Mortality - PCP CVC)


* PCP parents' cancer on patients' cancer mortality
cap drop interaction2 
g interaction2=low_ses*help_cancer

sum death_cancer if post==1, d
local mean=round(`r(mean)'*1000/1000, 0.00001)
local sd=round(`r(sd)'*1000/1000, 0.00001)

sum death_cancer if post==1 & low_ses==1
local mean_low=round(`r(mean)'*1000/1000, 0.00001) 


ttest death_cancer if post==1 & help3==0 , by(low_ses)
local mean0= round((`r(mu_2)'-`r(mu_1)')*1000/1000, 0.00001)

reghdfe death_cancer help_cancer low_ses interaction2 $patient_X $gp_X if post==1, a(gp_fe year) cluster(newgpyr)

outreg2 using "$table\TableD9.doc", append tex label keep(interaction2 help_cancer low_ses) nocons bdec(5) sdec(5) rdec(5)  addtext(Outcome mean,`mean', Outcome mean low-SES, `mean_low', Gradient  for high SES physicians, `mean0') ctitle(Cancer Mortality - PCP Cancer)


